package com.aliyun.edu.advanced.development.thread.achieve;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author xiaoming
 * @version 1.0
 * @date 2019-02-22 16:40
 * jdk1.5 高并发
 **/
public class demo3Callable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> ft1 = new FutureTask<String>(new MyThread5("线程A"));
        // 启动多线程
        new Thread(ft1).start();

        System.out.println(ft1.get());

    }
}

class MyThread5 implements Callable<String> {
    private String title;

    public MyThread5(String title) {
        this.title = title;
    }

    @Override
    public String call() throws Exception {
        for (int x = 0; x < 20; x++) {
            System.out.println(this.title + "卖票 x = " + x);
        }
        return "票卖完了, 下次再来吧";
    }

}
